﻿using System.Data.Entity.ModelConfiguration;
using yiCommerce.Core.Domain.Products;

namespace yiCommerce.Data.Mapping.Products
{
    public class ProductVariantAttributeMapping : EntityTypeConfiguration<ProductVariantAttribute>
    {
        public ProductVariantAttributeMapping()
        {
            this.ToTable("ProductVariant_ProductAttribute_Mapping");
            this.HasKey(pva => pva.Id);

            this.HasRequired(pva => pva.ProductVariant)
                .WithMany(pv => pv.ProductVariantAttributes)
                .HasForeignKey(pva => pva.ProductVariantId);
            
            this.HasRequired(pva => pva.ProductAttribute)
                .WithMany()
                .HasForeignKey(pva => pva.ProductAttributeId);
        }
    }
}